package top.wettis.chat.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.wettis.chat.mapper.ObjectivesMapper;
import top.wettis.chat.mapper.TaskMapper;
import top.wettis.chat.mapper.UserMapper;
import top.wettis.chat.pojo.DO.Objectives;
import top.wettis.chat.pojo.Query.GetAccont1;
import top.wettis.chat.service.IObjectivesService;

import java.util.List;

/**
 * <p>
 * 目标 服务实现类
 * </p>
 *
 * @author wettis
 * @since 2023-03-25
 */
@Service
public class ObjectivesServiceImpl extends ServiceImpl<ObjectivesMapper, Objectives> implements IObjectivesService {
@Autowired
private ObjectivesMapper objectivesMapper;

@Autowired
private UserMapper userMapper;

@Autowired
private TaskMapper taskMapper;


    @Override
    public void insert(int i, char week, String string, Integer toString , Integer order) {
        Objectives objectives = new Objectives();
        objectives.setUserId(i);
        objectives.setOrders(order);
        objectives.setWeek(week);
        objectives.setContent(string);
        objectives.setFinished(false);
        objectives.setDel(0);
        objectives.setLevel(toString);
        save(objectives);
    }

    @Override
    public void deleteAll(int userid) {
        objectivesMapper.deleteAll(userid);
    }

    @Override
    public List<Objectives> selectAll(int ui) {
        return objectivesMapper.selectAllById(ui);
    }

    @Override
    public int countgjd(int i, int userId) {
        return objectivesMapper.countgjd(i , userId);
    }

    @Override
    public Integer countsall(int userid) {
        return objectivesMapper.countt(userid);
    }

    @Override
    public Objectives selectCurPlan(int userid) {
        return objectivesMapper.selectcur(userid);
    }

    @Override
    public List<Objectives> selectByli(int userId, int curLevl) {
        return objectivesMapper.selectByli(userId , curLevl);
    }

    @Override
    public GetAccont1 get2(int userId) {
        GetAccont1 getAccont1 = new GetAccont1();
        int data1 = userMapper.selectAskTimes(userId);
        int data2 = userMapper.selectPunchTimes(userId);
        String d = userMapper.selectDate(userId);
        DateTime now = DateTime.now();
        DateTime of = DateTime.of(d, "yyyy-MM-dd");
        long between = DateUtil.between(of , now, DateUnit.DAY);

        getAccont1.setWendacish(data1);
        getAccont1.setXuexitianshu(data2);
        getAccont1.setCunzaitanshu(between);
        return getAccont1;
    }


}
